/**
 * 
 */
package com.cnhaimei.vod.net.dq;

import android.util.Log;

import com.cnhaimei.com.VODLog;
import com.cnhaimei.vod.bean.Singer;
import com.cnhaimei.vod.net.Data;
import com.cnhaimei.vod.net.dq.DQQueryResult.Field;
import com.cnhaimei.vod.net.temp.DQTable;
import com.cnhaimei.vod.util.Util;

/**
 * 歌星解析
 * 
 * @author jin001.wu@gmail.com <br>
 * @date 2011-7-30
 * 
 */
public class SingerParser extends DQParser {
	private static final String TAG = "SingerParser";
	DQQueryResult result;
	boolean ignoreBitmap;
	
	public SingerParser(DQQueryResult result) {
		super(result.getSnap());
		this.result = result;
	}
	
	public SingerParser(DQQueryResult result, boolean ignoreBitmap) {
		super(result.getSnap());
		this.result = result;
	}

	@Override
	public Data parse(byte[] in, DQHead head) {
		DQSinger rtn = new DQSinger();
		rtn.snap = result.getSnap();
		rtn.begin = Util.readInt(in, 0);
		rtn.count = Util.readInt(in, 4);

		Field nameField = result.getField(DQTable.StarCol.NAME);
		Field photoField = result.getField(DQTable.StarCol.PHOTO);
		
		if (Util.VLOG) {
			VODLog.e(TAG, " snap:" + rtn.snap);
			VODLog.e(TAG, " begin:" + rtn.begin);
			VODLog.e(TAG, " count:" + rtn.count);
		}

		for (int i = 0; i < rtn.count; i++) {
			Singer s = new Singer();
			String name = "";
			String photo = "";

			if (nameField != null) {
				name = Util.readString(in, 8 + i * result.getRecordBytes()
						+ nameField.posi, DQManager.ENCODING);
			}
			if (photoField != null) {
				photo = Util.readString(in, 8 + i * result.getRecordBytes()
						+ photoField.posi, DQManager.ENCODING);
			}

			s.setName(name);
			s.setImgName(photo);
//			if (!ignoreBitmap) {
//				Bitmap bt = Util.loadStar(photo);
//				s.setBitmap(bt);
//			}
			if (Util.DEBUG) {
				Log.e(TAG, "name:" + name);
				Log.e(TAG, "star:" + photo);
			}
			rtn.add(s);
		}
		return rtn;
	}

	public DQQueryResult getResult() {
		return result;
	}

	public void setResult(DQQueryResult result) {
		this.result = result;
	}

}
